package dk.app.resharylogo;

import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.os.Build;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		animateMove();
	}
	
	private void animateMove() {
		// blue move
		TranslateAnimation moveBlue = new TranslateAnimation(0, -280, 0, 0);
		moveBlue.setDuration(1000);
		moveBlue.setFillAfter(false);
		
		// orange move
		TranslateAnimation moveOrange = new TranslateAnimation(0, 280, 0, 0);
		moveOrange.setDuration(1000);
		moveOrange.setFillAfter(false);
		moveOrange.setAnimationListener(new Animation.AnimationListener() {
			@Override
			public void onAnimationStart(Animation animation) { }
			@Override
			public void onAnimationRepeat(Animation animation) { }
			@Override
			public void onAnimationEnd(Animation animation) { animateRotate(); }
		});
		
		// start move animations
		ImageView imgBlue = (ImageView)findViewById(R.id.blue);
		ImageView imgOrange = (ImageView)findViewById(R.id.orange);
		imgBlue.startAnimation(moveBlue);
		imgOrange.startAnimation(moveOrange);
	}
	
	private void animateRotate() {
		// hide blue and orange
		((ImageView)findViewById(R.id.blue)).setVisibility(View.GONE);
		((ImageView)findViewById(R.id.orange)).setVisibility(View.GONE);
		// circle rotate
	    RotateAnimation rotate = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
	    rotate.setInterpolator(new LinearInterpolator());
	    rotate.setRepeatCount(Animation.INFINITE);
	    rotate.setDuration(2000);
	    // start rotate
		ImageView imgCircle = (ImageView)findViewById(R.id.circle);
		imgCircle.setVisibility(View.VISIBLE);
		imgCircle.startAnimation(rotate);
	}


}
